package com.example.stus.contorller;

import com.example.stus.entity.GradeEntity;
import com.example.stus.entity.StuInformation;
import com.example.stus.resposistory.GradeResposistory;
import com.example.stus.resposistory.StuInformationReposistory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/GradeEntity")
public class GradeController {
    @Autowired
    private GradeResposistory gradeResposistory;

    //添加操作
    @PostMapping("/save")
    public String save(@RequestBody GradeEntity gradeEntity){
        GradeEntity result =  gradeResposistory.save(gradeEntity);
        if ( result!=null )
        {
            return "success";
        }
        else{
            return "error";
        }
    }
    //从前端接收要修改的Id（sno）
    @GetMapping("/findByCname/{cname}")
    public GradeEntity findByCname(@PathVariable("cname") String cname){
        return gradeResposistory.findByCname(cname);
    }
    @PutMapping("/update")
    public String update(@RequestBody GradeEntity gradeEntity){
        GradeEntity result = gradeResposistory.save(gradeEntity);
        if ( result != null )
        {
            return "success";
        } else{
            return "error";
        }
    }
}
